 <template>
    <section>
        <!--搜索工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px; ">
            <el-form :inline="true" :model="filters" ref="filters" label-width="80px">
                <el-form-item prop="year">
                    <el-select
                            placeholder="年份" v-model="filters.year" size="18px">
                        <el-option :key="item" :label="item" :value="item"
                                   v-for="item in options.years"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item prop="check_unit_name">
                    <el-input
                            placeholder="高校名称"
                            v-model.trim="filters.check_unit_name">
                    </el-input>
                </el-form-item>
                <el-form-item prop="check_status">
                    <el-select
                            placeholder="状态" v-model="filters.check_status" size="18px">
                        <el-option value="" label="全部"></el-option>
                        <el-option :key="value" :label="txt" :value="value"
                                   v-for="(txt, value) in options.records_status"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button @click="reset">重置</el-button>
                </el-form-item>

            </el-form>
        </el-col>


        <!--搜索结果表格-->
        <el-table
                :data="tableData"
                stripe
                v-loading="listLoading"
                style="width: 100%;">
            <el-table-column
                    align="center"
                    label="序号"
                    width="80px"
                    type="index">
            </el-table-column>
            <el-table-column
                    label=""
                    width="50px"
                    align="center">
                <template slot-scope="scope">
                    <img class="uint_logo" :src="scope.row.check_unit_logo && scope.row.check_unit_logo.path ? scope.row.check_unit_logo.path : ''"/>
                </template>
            </el-table-column>

            <el-table-column
                    label="高校名称"
                    prop="check_unit_name"
                    align="center">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="不合格检查项数量"
                     prop="check_desc_count">
            </el-table-column>
           <!-- <el-table-column
                    align="center"
                    label="不合格数量"
                    prop="check_desc_unqualified_count">
            </el-table-column>-->
            <el-table-column
                    align="center"
                    label="更新时间"
                    prop="gmt_modified">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="状态"
                    :formatter="statusFormat"
                    prop="check_status">
            </el-table-column>
            <el-table-column label="操作" align="left" width="200">
                <template slot-scope="scope">
                    <el-button
                            type="primary" plain
                            @click="view(scope.row.id, scope.row.check_status)">详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24" class="toolbar">
            <el-pagination
                    style="text-align: center;"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-size="pager.page_size"
                    :page-sizes="pager.sizes"
                    background
                    :current-page="pager.page_current"
                    layout="prev,pager,next,sizes,total"
                    :total="pager.total">
            </el-pagination>
        </el-col>

    </section>
</template>

<script>
    import * as api from '../../api/records_api'
    import dict from '../../common/js/dict';

    export default {
         name:'检查作业列表',
        data() {
            return {
                listLoading: false,
                currentYear: 2018,
                //表格数据
                tableData: [],
                filters: {
                    year: '',
                    check_unit_name: '',
                    check_status: '',
                },
                //分页设置
                pager: {
                    sizes: [10, 20, 30, 40, 50],
                    total: 0,
                    page_size: 10,
                    page_current: 1
                },
                options: {
                    years: [],
                    records_status: dict.records_status
                }
            }
        },
        methods: {
            statusFormat(row, column) {
                if (row) {
                    return this.options.records_status[row[column.property]];
                }
                return '';
            },
            // 详情
            view(id, status) {
                if(status == "1"){
                    this.$router.push('/records/view/' + id);
                }
                else{
                    this.$router.push('/records/detail/' + id);
                }
            },
            //分页page_size发生改变
            handleSizeChange(val) {
                this.pager.page_current = 1;
                this.pager.page_size = val;
                this.getRecords();
            },
            //分页page_current发生改变
            handleCurrentChange(val) {
                this.pager.page_current = val;
                this.getRecords();
            },
            search() {
                this.pager.page_current = 1;
                this.getRecords();
            },
            getRecords() {

                this.listLoading = true;  //显示loading

                let condition = this.filters;
                let params = {
                    page_size: this.pager.page_size,
                    page_current: this.pager.page_current,
                    condition: condition
                };


                api.getRecordsList(params).then((res) => {
                    if (res.data.status == 200) {
                        this.listLoading = false;  //隐藏loading
                        let result = JSON.parse(res.data.datas);
                        this.tableData = result.items;
                        this.pager.total = result.total;
                    } else {
                        if (res.data.status == 401) {
                            this.$router.push('/login');
                        }
                        this.$message.error(res.data.status + " " + res.data.msg);
                    }
                });
            },
            reset() {
                this.$refs['filters'].resetFields();
                this.filters.year = this.currentYear;
                this.pager.page_current = 1;
                this.getRecords();
            },
            initYears() {
                this.currentYear = (new Date()).getFullYear();
                this.filters.year = this.currentYear;
                for (let i = this.currentYear; i >= 2018; i--) {
                    this.options.years.push(i);
                }
            },
            //初始化页面
            initData() {
                this.initYears();
                this.getRecords();
            }
        },
        mounted() {
            this.$nextTick(function () {
                this.initData();
            })
        }
    }
</script>

<style scoped>

    .uint_logo{
        width: 35px;
    }
</style>
